<?php

function unproses(){
	$periode_id = get_periode_gaji();
	$last_periode_id = get_last_periode_id($periode_id) ;
	if($last_periode_id <= 0){
		return false ;
	}		
	//validasi selisih periode gaji dan absen tidak boleh lebih dari 1 bulan
	$temps=my_get_data_by_id('pr_periode','periode_id',get_periode_absen()) ;
	$periode_absen = date('m' , strtotime($temps['tanggal'])) +  $temps['tahun'] * 12;
	$temps=my_get_data_by_id('pr_periode','periode_id',$last_periode_id) ;
	$periode_gaji = date('m' , strtotime($temps['tanggal'])) +  $temps['tahun'] * 12 ;
	if($periode_absen - $periode_gaji > 1 ){
		//var_dump($periode_absen); var_dump($periode_gaji); exit;
		return false ;
	}

	$query = "DELETE FROM pr_gaji WHERE periode_id=0";
	$result = my_query($query);	
	
	$query = "UPDATE pr_gaji SET 
		periode_id = 0 WHERE periode_id=".$last_periode_id;
	$result = my_query($query);		
	$query = "UPDATE pr_gaji_komponen SET 
		periode_id = 0 WHERE periode_id=".$last_periode_id;
	$result = my_query($query);		
	$query = "UPDATE pr_gaji_pajak SET 
		periode_id = 0 WHERE periode_id=".$last_periode_id;
	$result = my_query($query);	

	$query = "DELETE FROM pr_penyesuaian WHERE reset='Y'";
	$result = my_query($query);	
	
	$query = "TRUNCATE TABLE pr_gaji_upload_view";
	$result = my_query($query);		

	$query = "UPDATE pr_periode SET gaji = 'Void' WHERE gaji ='Active'" ;
	$result = my_query($query);		
	
	$datas = array(
		'gaji'=>my_type_data_str('Active'),	
	);
	my_update_record('pr_periode','periode_id',$last_periode_id,$datas);	
	return true ;
}	
	
	